//
//  ZXCulturePartView.m
//  ZiJinLian
//
//  Created by 震霄 张 on 2018/3/11.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "ZXCulturePartView.h"
#import "ZXPartGoodsView.h"
@interface ZXCulturePartView()
@property (weak, nonatomic) IBOutlet UIImageView *headView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgBtnH;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet UIView *countBgView;

@end

@implementation ZXCulturePartView

+(instancetype)zxculturePartView
{
	return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}
-(void)awakeFromNib
{
	[super awakeFromNib];
	self.autoresizingMask = UIViewAutoresizingNone;
	self.headH.constant = MainW/16*9;
	self.bgBtnH.constant = self.headH.constant;
	self.scrollView.showsHorizontalScrollIndicator = NO;
	self.countBgView.layer.cornerRadius = 3;
	self.countBgView.clipsToBounds = YES;
}
-(void)setModel:(HomeCultureModel *)model
{
	_model = model;
	
	[self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
	
	for (int i = 0; i<model.skuList.count; i++) {
		HomeCulGoodModel *goodModel = model.skuList[i];
		ZXPartGoodsView *goodView = [ZXPartGoodsView zxpartGoodsView];
		goodView.model = goodModel;
		goodView.frame = CGRectMake(10+(100+10)*i, 0, 100, 160);
		[self.scrollView addSubview:goodView];
	}
	self.scrollView.contentSize = CGSizeMake((100+10)*model.skuList.count, 160);
	
	[self.headView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@""]];
	self.numLabel.text = [NSString stringWithFormat:@"%ld",model.count];
}
- (IBAction)btnClick:(id)sender {
	NSMutableDictionary *dic = [NSMutableDictionary dictionary];
	[dic setValue:@"1" forKey:@"type"];
	[dic setValue:self.model.imageLink forKey:@"value"];
	[[NSNotificationCenter defaultCenter]postNotificationName:@"jumpOther" object:nil userInfo:dic];
}
@end
